package com.ccf.business.etl.client;

import com.service.database.config.DatabaseConfig;
import com.service.database.model.DataModel;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 描述：
 * 数据调用调用客户端
 * @author xianggj
 * @Date 2022/2/21 18:22
 **/
@FeignClient("business-database")
@Component
public interface DatabaseClient {

    /**
     * 返回表数据
     * @param sid 资源id
     * @param tableName 表名
     * @return
     */
    @RequestMapping(value = "/database/remote/getTableData", method = RequestMethod.GET)
    DataModel getTableData(@RequestParam("sid") String sid, @RequestParam("tableName") String tableName);

    /**
     * 添加表缓存
     * @param sid 资源id
     * @param tableName 表名
     * @param remark
     * @return
     */
    @RequestMapping(value = "/database/remote/saveTableCache", method = RequestMethod.POST)
    void saveTableCache(@RequestParam("sid") String sid,
                        @RequestParam("tableName") String tableName,
                        @RequestParam(value = "remark", required = false) String remark);

    /**
     * 返回表配置
     * @param sid 资源id
     * @param tableName 表名
     * @return
     */
    @RequestMapping(value = "/database/remote/getConfig", method = RequestMethod.GET)
    DatabaseConfig getConfig(@RequestParam("sid") String sid, @RequestParam("tableName") String tableName);

    /**
     * 返回表详情
     * @param sid 资源id
     * @param tableName 表名
     * @return
     */
    @RequestMapping(value = "/database/remote/getTableDesc", method = RequestMethod.GET)
    List<Map<String, Object>> getTableDesc(@RequestParam("sid") String sid, @RequestParam("tableName") String tableName);

    /**
     * 查询可操作的表
     * @param sid
     * @return
     */
    @RequestMapping(value = "/database/remote/listTablesExcludeSelfBuilt", method = RequestMethod.GET)
    List<String> listTablesExcludeSelfBuilt(@RequestParam("sid") String sid);
}
